package com.tencent.web.controller;

import com.github.pagehelper.PageInfo;
import com.tencent.entity.Order;
import com.tencent.entity.Pagination;
import com.tencent.entity.SetMeal;
import com.tencent.service.OrderMemberService;
import com.tencent.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author: @date: 2022/8/15 11:27
 * @description:
 */
@RestController
@RequestMapping("/showOrderMember1")
public class ShowOrderMemberController {

    @Autowired
    private OrderMemberService orderMemberService;

    @Autowired
    private OrderSettingService orderSettingService;




    @GetMapping("/test")
    public List<Order> getTest(String str){
        return orderMemberService.getTest(str);
    }

    @PostMapping
    public PageInfo<Order> findByPage(Pagination pagination) {
        PageInfo<Order> list = orderMemberService.selectOrderByName(pagination);
        return list;
    }

    @GetMapping("/delete/{id}")
    public int deleteByInfo(@PathVariable int id) {
        Date date = orderMemberService.deleteByIdInfo(id);
        int i = orderSettingService.updateDelReservations(date);

        return i;
    }

    @GetMapping("/updateById/{id}")
    public int updateByInfo(@PathVariable int id) {
        return orderMemberService.updateByIdInfo(id);

    }

    @PostMapping("/add")
    public int addInfo(@RequestBody Order order) {
        long time = order.getOrderDate().getTime();
        time += 1000 * 60 * 60*24;
        Date date = new Date(time);
        order.setOrderDate(date);

        int n = orderMemberService.addInfo(order);
        Date orderDate = order.getOrderDate();

        System.out.println(orderDate);
        orderSettingService.updateReservations(orderDate);

        return n;
    }

    @GetMapping("/findAll")
    public List<SetMeal> findAll() {
        return orderMemberService.findAll();

    }


}